(function($) {
    $.submitForm = function(t, successFunc) {
        $(t).parents('form').validate({
            errorClass: 'form-error',
            errorElement: 'div',
            submitHandler: function(form) {
                $(form).ajaxSubmit({
                    dataType: 'json',
                    beforeSubmit: function(formParams, jqForm, options) {
                        //Disable button
                        $(".form-button").addClass("disabled");
                        $(".form-button").attr("disabled","disabled");

                        //Load image
                        $(jqForm).find(".ajax-load").show();
                        this.form = jqForm;
                        return true;
                    },
                    success: function(responseText, statusText) {
                        $(".form-button").removeAttr("disabled");
                        $(".form-button").removeClass("disabled");

                        //Load notification
                        $(".ajax-load").hide();
                        if (successFunc == undefined) {
                            $(this.form).find(".ajax-message").htmlTimer(responseText.message, 5000);
                        }
                        else {
                            successFunc(this.form, responseText);
                        }
                    }
                });
            }
        });
    };

})(jQuery);

$(function(){
    $(".ajax-submit").click(function(){
        $.submitForm(this);
    });
});

